package com.jike.jkgame;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.jike.jkgame.data.MissionReward;

public class RewardsFrameDialog extends DialogFragment implements OnClickListener {
	
	public static RewardsFrameDialog newInstance(MissionReward reward) {
		RewardsFrameDialog f = new RewardsFrameDialog();

		Bundle args = new Bundle();
		args.putSerializable("reward", reward);
		f.setArguments(args);

		return f;
	}
	
	private MissionReward mReward;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle args = getArguments();
		mReward = (MissionReward)args.getSerializable("reward");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		getDialog().requestWindowFeature(STYLE_NO_TITLE);
		
		if (mReward == null) {
		    this.dismiss();
		}
		
		View v = inflater.inflate(R.layout.rewardsdialog_layout, container,
				false);
		v.findViewById(R.id.btn_close).setOnClickListener(this);
		v.findViewById(R.id.btn_ok).setOnClickListener(this);
		Rect displayRectangle = new Rect();
		Window window = getDialog().getWindow();
		window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
		v.setMinimumWidth((int)(displayRectangle.width() * 0.7f));
		v.setMinimumHeight((int)(displayRectangle.height() * 0.8f));
		TextView tv = (TextView)v.findViewById(R.id.tv_rewards);
		tv.setText(mReward.getFromatedString());
		
		return v;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_ok:
		case R.id.btn_close:
			getDialog().dismiss();
			break;
		default:
			break;
		}

	}

}
